<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组的扩展方法</title>
</head>
<body>
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</body>


<script type="text/javascript">

  //数组的方法  from()  of()
  // from() 将伪数组转换成真正的数组
  function add() {
    console.log(arguments)
    // es5转换
    let arr_es5 = [].slice.call(arguments)
    console.log(arr_es5)

    // es6转换
    let arr_es6 = Array.from(arguments)
    console.log(arr_es6);
  }
  add(2, 4, [6, 8], '10')

  let list = document.querySelectorAll('li') 
  // 通过from转换数组
  console.log('from', Array.from(list));
  // 通过扩展运算符转换数组
  console.log('...', [...list])


  // Array.of()
  let arr = Array.of(2, 4, [6, 8], '10')
  console.log(arr);

  console.log([1, 2, 4, 6, 7, 8, 9].copyWithin(0, 5));


  // findIndex()
  let arr1 = [1, 2, -10, -20, 9, 3]
  let numIndex = arr1.findIndex(n => n < 0)
  console.log(numIndex)

  let arr2 = ['a', 'b', 'c']
  // keys()
  for(let index of arr2.keys()) {
    console.log('index ==> ', index)
  }

  // values()
  for(let ele of arr2.values()) {
    console.log('ele ==>', ele)
  }

  // entries()
  for(let [index, ele] of arr2.entries()) {
    console.log(index, ele)
  }

  // includes，替换indexOf()，返回一个布尔值，表示某个元素是否在数组中
  console.log(arr2.includes('b'))
  console.log(arr2.includes('d'))

    
</script>
</html>